var sourceData = [];
var chartData = [];
var mirrorMenu = {};
var globalOptions = {
    width:0,
    height:0,
    speed:10,
    dataLength:1000,
}
var myChart = null;
var myChart1 = null;
var myChart2 = null;
var myChart3 = null;
var myChart4 = null;
var myChart5 = null;

var chartMenu = 'pressure'
localStorage.speed = parseInt(localStorage.speed || globalOptions.speed)
localStorage.dataLength = parseInt(localStorage.dataLength || globalOptions.dataLength)

$(document).ready(function () {
    init();
    $("#speed").val(localStorage.speed)
    globalOptions.speed = localStorage.speed
    $("#length").val(localStorage.dataLength)
    globalOptions.dataLength = localStorage.dataLength
})
window.onresize = function(){
    init();
    myChart.resize();
    myChart.setOption(option);
    myChart1.resize();
    myChart1.setOption(option1);
    myChart2.resize();
    myChart2.setOption(option2);
    myChart3.resize();
    myChart3.setOption(option3);
    myChart4.resize();
    myChart4.setOption(option4);
    myChart5.resize();
    myChart5.setOption(option5);
}
function init() {
    globalOptions.width = $('body').width()
    globalOptions.height = $('body').height() - 80
    $("#chart").css({width:(globalOptions.width * 0.833333 -30)+'px',height:(globalOptions.height - 50)+'px'})
    $(".more-chart").css({width:(globalOptions.width * 0.416667 -30)+'px',height:(globalOptions.height/3 -60)+'px'})
    myChart = echarts.init(document.getElementById('chart'));
    myChart1 = echarts.init(document.getElementById('chart1'));
    myChart2 = echarts.init(document.getElementById('chart2'));
    myChart3 = echarts.init(document.getElementById('chart3'));
    myChart4 = echarts.init(document.getElementById('chart4'));
    myChart5 = echarts.init(document.getElementById('chart5'));
}
var fileLoading = 0;
//js 读取文件
function jsReadFiles(files) {
    if (files.length) {
        var file = files[0];
        var reader = new FileReader();//new一个FileReader实例
        reader.onload = function() {
            $("#loading").append("<br/>数据计算中。。。");
            //debugger;
            var _self = this
            setTimeout(function(){
                var arr = _self.result.split("\n").map(function(a){return a.split(',')});
                sourceData = arr[0].map(function(col, i) {
                    return arr.map(function(row) {return row[i];})
                });
                sourceData.forEach(function (t,i) {
                    mirrorMenu[t.shift()] = i
                })
            },10)
        }
        reader.onloadstart = function () {
            $("#loading").text("");
            $("#loading").append("文件读取中")
            fileLoading = setInterval(function () {
                $("#loading").append(">> ")
            },10)
        }
        reader.onloadend = function () {
                clearInterval(fileLoading);
            setTimeout(function() {
                $("#loading").append("<br/>数据加载完成")
            },11)
        }
        reader.readAsText(file);
    }
}
function speedChange() {
    localStorage.speed= globalOptions.speed = parseInt($("#speed").val());
}
function speedLength() {
    localStorage.dataLength= globalOptions.dataLength = parseInt($("#length").val());
}